#ifndef __NCU_H__
#define __NCU_H__
#include <stdint.h>
#include "ncu.h"
#include "ncuopt.h"

#define DMAIN_DMAOUT 0
#define DMAIN_BYPASS 1
#define BYPASS_DMAOUT 2
#define BYPASS_BYPASS 3

#define ncu_frm_psn_max_num 0
#define ncu_frm_sta_max_num 0

#define NCU_IOCTL_MAGIC 'n'
#define IOCTL_NCU_WAIT _IOR(NCU_IOCTL_MAGIC, 1, uint32_t)
#define IOCTL_NCU_COMP_INIT _IOW(NCU_IOCTL_MAGIC, 2, uint32_t)

#define PP_IOCTL_MAGIC 'p'
#define IOCTL_PP_WAIT _IOR(PP_IOCTL_MAGIC, 1, uint32_t)
#define IOCTL_PP_COMP_INIT _IOW(PP_IOCTL_MAGIC, 2, uint32_t)


typedef struct{
    uint32_t OutMode;
    uint32_t InMode;
    uint32_t YStaEn;
    uint32_t YPsnEn;
    uint32_t YST1En;
    uint32_t YST2En;
    uint32_t UvStaEn;
    uint32_t UvPsnEn;
    uint32_t UvST1En;
    uint32_t UvST2En;
    uint32_t UST2En;
    uint32_t VST2En;
}mode_para;

typedef struct {
    mode_para mode;
    uint32_t frm_w;
    uint32_t frm_h;
} ncu_src_attr;

typedef struct {
    uint32_t sta_y_blk_w;
    uint32_t sta_y_blk_h;
    uint32_t sta_uv_blk_w;
    uint32_t sta_uv_blk_h;
	uint32_t sta_y_stride;
	uint32_t sta_uv_stride;
} ncu_sta_attr;

typedef struct {
    uint32_t sta_y_blk_w;
    uint32_t sta_y_blk_h;
    uint32_t sta_w_num;
    uint32_t sta_h_num;
	uint32_t sta_y_stride;
} pp_sta_attr;

typedef struct {
    uint32_t psn_y_stride;
    uint32_t psn_uv_stride;
} ncu_psn_attr;

typedef struct {
    uint32_t ave;
    uint32_t sgm_corr_x;
    uint32_t sgm_corr_y;
    uint32_t sgm_corr_s;
    uint32_t sgm_pfr_x;
    uint32_t sgm_pfr_y;
    uint32_t sgm_pfr_s;
    uint32_t pfr_diff0;
    uint32_t pfr_diff1;
    uint32_t fluct_hg_diff;
    uint32_t fluct_uhg_br_diff;
    uint32_t fluct_uhg_dk_diff;
    uint32_t pxl_diff_thres;    //only for y
} ncu_fs_para;

typedef struct {

    uint32_t ave;              //for uv ,use as con_para
    uint32_t sgm_bdv_x_0;
    uint32_t sgm_bdv_y_0;
    uint32_t sgm_bdv_s_0;
    uint32_t sgm_bdv_x_1;
    uint32_t sgm_bdv_y_1;
    uint32_t sgm_bdv_s_1;
    uint32_t sgm_bdv_adj_0;
    uint32_t sgm_bdv_adj_1;
    uint32_t sgm_bdv_adj_2;
    uint32_t sgm_bdv_adj_3;
    uint32_t pxl_diff_thres;    //for uv ,use as pxl_line_thres
    uint32_t statis_par;          //only for y
    uint32_t ref_wei;            //only for y
    uint32_t coner_par;
} ncu_se_para;

typedef struct {
    uint32_t sgm_edge_x_0;     //for uv ,use as sgm_edge_x
    uint32_t sgm_edge_x_1;
    uint32_t sgm_edge_y_0;
    uint32_t sgm_edge_y_1;
    uint32_t sgm_edge_s_0;
    uint32_t sgm_edge_s_1;
    uint32_t sgm_pfr_x_0;
    uint32_t sgm_pfr_x_1;
    uint32_t sgm_pfr_y_0;
    uint32_t sgm_pfr_y_1;
    uint32_t sgm_pfr_s_0;
    uint32_t sgm_pfr_s_1;
    uint32_t org_sup_thres;  //only for y
    uint32_t blur_par;     //only for uv
    uint32_t lum_par;       //only for uv
} ncu_fusion_blk;

typedef struct {
    uint32_t ave;
    ncu_fusion_blk y_s;
    ncu_fusion_blk y_m;
} ncu_yfusion_para;

typedef struct {
    uint32_t mv_judge_thres;
    ncu_fusion_blk uv_s;
    ncu_fusion_blk uv_m;
} ncu_uvfusion_para;

typedef struct {
    uint32_t psn_par0;
    uint32_t psn_par1;
    uint32_t sta_ave;           //y
    uint32_t sta_size;          //for uv ,use as sta_blk_size
    uint32_t sta_size_num;      //for uv ,use as sta_blk_size
    uint32_t sta_size_incr;     //for uv ,use as sta_blk_size
    uint32_t sta_mv_blk_adj;      //for uv,use as sta_blk_adj
    uint32_t sta_diff_thres;
    uint32_t sta_mv_num_thres;      //for uv,use as sta_num_thres
    uint32_t sta_lum_area;       //y
    uint32_t sta_fals_color_par;   //uv

} ncu_psn_sta_para;

typedef struct {
    uint32_t sgm_p_x;
    uint32_t sgm_p_y;
    uint32_t sgm_p_s;
    uint32_t gaus_sgm;
} ncu_y_st2_para;

typedef struct {
    uint32_t psn_max_num;
    uint32_t sta_max_num;

    uint32_t sta_y_blk_w;
    uint32_t sta_y_blk_h;
    uint32_t sta_uv_blk_w;
    uint32_t sta_uv_blk_h;

    uint32_t cut_value;
    ncu_fs_para yFs;
    ncu_se_para ySe;
    ncu_fs_para uvFs;
    ncu_se_para uvSe;
    ncu_yfusion_para yFusion;
    ncu_uvfusion_para uvFusion;
    ncu_psn_sta_para yPsnSta;
    ncu_psn_sta_para uvPsnSta;
    ncu_y_st2_para ySt2;
} ncu_filter_para;

typedef struct {
    uint32_t handle;
    uint32_t bufaddr;
    uint32_t bufsize;
    uint32_t ysize;
    uint32_t uvsize;
    uint32_t y_addr;
    uint32_t u_addr;
    uint32_t v_addr;
    uint32_t y_paddr;
    uint32_t u_paddr;
    uint32_t v_paddr;
    uint32_t cnt;
} ncu_buf_sta;

typedef struct {
    uint32_t handle;
    uint32_t bufaddr;
    uint32_t bufsize;
    uint32_t y_addr;
    uint32_t u_addr;
    uint32_t v_addr;
    uint32_t y_paddr;
    uint32_t u_paddr;
    uint32_t v_paddr;
} ncu_buf_psn;

typedef struct {
    uint32_t handle;
    uint32_t bufaddr;
    uint32_t bufsize;
    uint32_t y_addr;
    uint32_t y_paddr;
    uint32_t uv_addr;
    uint32_t uv_paddr;
} ncu_buf;

typedef struct {
	ncu_src_attr src_attr;
	ncu_sta_attr sta_attr;
	ncu_psn_attr psn_attr;
	ncu_buf cur_buf;
	ncu_buf ref_buf0;
	ncu_buf ref_buf1;
	ncu_buf_sta sta_buf;
	ncu_buf_psn psn_buf;
	int fd;
	int fd_pp;
} ncu_info;

int ncu_fun_ctrl(uint32_t funcs);
int ncu_in_mode(uint32_t mode);
int ncu_out_mode(uint32_t mode);
int ncu_set_stride(uint32_t stride);
int ncu_set_ref0_buffer(uint32_t yaddr, uint32_t uvaddr);
int ncu_set_ref1_buffer(uint32_t yaddr, uint32_t uvaddr);
int ncu_set_cur_buffer(uint32_t yaddr, uint32_t uvaddr);
int ncu_set_sta_buffer(uint32_t yaddr, uint32_t uaddr, uint32_t vaddr);
int ncu_set_psn_buffer(uint32_t yaddr, uint32_t uaddr, uint32_t vaddr);
int ncu_set_frame_size(uint32_t w, uint32_t h);
int ncu_init();
uint32_t ncu_get_info();
int ncu_config_ready();
int ncu_get_clkcnt();
int ncu_reset();
int ncu_start();
int ncu_stop();
int ncu_first_frame();
uint32_t ncu_frame_end();
int ncu_set_yFs(ncu_filter_para *NcuFilter);
int ncu_set_ySe(ncu_filter_para *NcuFilter);
int ncu_set_uvFs(ncu_filter_para *NcuFilter);
int ncu_set_uvSe(ncu_filter_para *NcuFilter);
int ncu_set_yFusion(ncu_filter_para *NcuFilter);
int ncu_set_uvFusion(ncu_filter_para *NcuFilter);
int ncu_set_y_sta_psn(ncu_filter_para *NcuFilter);
int ncu_set_uv_sta_psn(ncu_filter_para *NcuFilter);
int ncu_set_stage2(ncu_filter_para *NcuFilter);
int ncu_get_value(ncu_filter_para *NcuFilter);
int ncu_set_filter_allpara();
int ncu_set_src_dst_stride(uint32_t width);
int ncu_set_psn_stride(uint32_t y, uint32_t uv);
int ncu_set_sta_stride(uint32_t y, uint32_t u, uint32_t v);
int ncu_set_sta_size(uint32_t frm_w, uint32_t frm_h, uint32_t y_blk_w, uint32_t y_blk_h, uint32_t uv_blk_w, uint32_t uv_blk_h);
uint32_t ncu_get_info();
uint32_t pp_frame_end();
int ncu_all_buf_config(ncu_info *info, uint32_t isdmain);
int ncu_config(ncu_opt *opt);
#endif
